package com.fastjpa.controller;

import java.util.List;
import org.springframework.web.bind.annotation.*;
import com.fastjpa.vo.TeacherVo;
import com.fastjpa.service.TeacherService;
import com.fastjpa.ResponseData;
import com.efeichong.common.PageData;
import lombok.RequiredArgsConstructor;

/**
* @author admin
* @date 2022/07/17
* @description 教师
*/
@RestController
@RequestMapping("/teacher")
@RequiredArgsConstructor
public class TeacherController {

    private final TeacherService teacherService;

    @GetMapping(value = "/getInfo")
    public ResponseData<TeacherVo> getInfo(@RequestParam("id") Long id) {
        return new ResponseData(teacherService.getInfo(id));
    }

    @GetMapping("/page")
    public ResponseData<PageData<TeacherVo>> page(TeacherVo teacherVo) {
        return new ResponseData(teacherService.selectByPage(teacherVo));
    }

    @PostMapping("insert")
    public ResponseData insert(@RequestBody TeacherVo teacherVo) {
        teacherService.insertTeacher(teacherVo);
        return new ResponseData();
    }

    @PostMapping("update")
    public ResponseData update(@RequestBody TeacherVo teacherVo) {
        teacherService.updateTeacher(teacherVo);
        return new ResponseData();
    }

    @GetMapping("/deleteByIds")
    public ResponseData deleteTeacherByIds(@RequestParam("ids") List<Long> ids) {
        teacherService.deleteByIds(ids);
        return new ResponseData();
    }

    @GetMapping("/deleteById")
    public ResponseData deleteTeacherById(@RequestParam("id") Long id) {
        teacherService.deleteById(id);
        return new ResponseData();
    }

}
